package com.bytedance.framwork.core.monitor;

import android.app.ActivityManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Build;
import android.os.Process;
import android.text.TextUtils;
import android.util.Log;

import com.bytedance.frameworks.core.a.c.a;
import com.bytedance.frameworks.core.a.j;
import com.bytedance.frameworks.core.a.k;
import com.bytedance.frameworks.core.a.l;
import com.ss.android.common.util.NetworkUtils;
import com.ss.android.http.legacy.a.NameValueImpl;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import inline.NetworkDemo;
import inline.PackageUtils;

public class c implements com.bytedance.frameworks.core.a.c.a, com.bytedance.frameworks.core.a.j, com.bytedance.frameworks.core.a.k {
    final class c$a {
        long a;
        long b;
        double c;
        double d;
        double e;

        public c$a(long arg4, double arg6, double arg8, double arg10) {
            this.a = arg4;
            this.c = arg6;
            this.d = arg8;
            this.b = 1;
            this.e = arg10;
        }
    }

    public static final class c$b {
        public c$b() {

        }

        public static Map a() {
            HashMap v1 = new HashMap();
            ArrayList v0 = new ArrayList();
            NetworkUtils.a(v0);
            Iterator v2 = ((List) v0).iterator();
            while (v2.hasNext()) {
                Object v0_1 = v2.next();
                String v3 = ((NameValueImpl) v0_1).name;
                String v0_2 = ((NameValueImpl) v0_1).value;
                if (TextUtils.isEmpty(((CharSequence) v3))) {
                    continue;
                }

                if (TextUtils.isEmpty(((CharSequence) v0_2))) {
                    continue;
                }

                ((Map) v1).put(v3, v0_2);
            }

            return ((Map) v1);
        }
    }

    public interface c$c {
        void c();
    }

    private volatile int A;
    private volatile JSONObject B;
    private volatile JSONObject C;
    private volatile List D;
    private volatile List E;
    private volatile List F;
    private volatile long G;
    private volatile long H;
    private volatile long I;
    private volatile long J;
    private volatile long K;
    private static volatile int L;
    private volatile long M;
    private static com.bytedance.framwork.core.monitor.c.c$b N;
    private static List O;
    private volatile boolean P;
    private volatile long Q;
    private volatile int R;
    private volatile int S;
    private volatile long T;
    private volatile long U;
    private volatile int V;
    private volatile boolean W;
    private volatile boolean X;
    private volatile long Y;
    private volatile boolean Z;
    public Context a;
    private static volatile List aa;
    private static volatile boolean ab;
    private volatile com.bytedance.article.common.a.b.a ac;
    private volatile com.bytedance.article.common.a.c.a ad;
    private volatile boolean ae;
    private volatile boolean af;
    private static volatile boolean ag;
    private c$a ah;
    private BroadcastReceiver ai;
    public com.bytedance.frameworks.core.a.b.b$a b;
    public volatile int c;
    public volatile int d;
    public volatile JSONObject e;
    public volatile List<String> f;
    public volatile boolean g;
    public volatile boolean h;
    public volatile int i;
    public volatile boolean j;
    public volatile String k;
    public volatile long l;
    public String m;
    public long n;
    public long o;
    public long p;
    public int q;
    private static volatile com.bytedance.framwork.core.monitor.c r;
    private JSONObject s;
    private volatile long t;
    private volatile long u;
    private volatile int v;
    private volatile int w;
    private volatile int x;
    private volatile int y;
    private volatile int z;

    static {
        L = 1;
        O = new ArrayList(Arrays.asList(new String[]{"http://mon.snssdk.com/monitor/appmonitor/v2/settings", "http://monsetting.toutiao.com/monitor/appmonitor/v2/settings"}));
        aa = new ArrayList();
    }

    private c(Context arg9, JSONObject arg10, com.bytedance.framwork.core.monitor.c.c$b arg11) {

        this.t = 0;
        this.z = 1;
        this.J = 300;
        this.K = 60;
        this.j = true;
        this.Q = 0;
        this.S = 0;
        this.T = 0;
        this.U = 0;
        this.V = 0;
        this.X = true;
        this.Y = 0;
        this.ai = new com.bytedance.framwork.core.monitor.e(this);
        ab = true;
        this.a = arg9.getApplicationContext();
        this.s = arg10;
        N = arg11;
        com.bytedance.frameworks.core.a.c.a(((a) this));
        android.support.design.a.g = ((j) this);
        com.bytedance.frameworks.baselib.a.d.a(new f());
        this.b = new com.bytedance.frameworks.core.a.b.b$a(arg9.getApplicationContext(), ((k) this));
        this.ac = new com.bytedance.article.common.a.b.a(arg9);
        this.ad = new com.bytedance.article.common.a.c.a(arg9);
        SharedPreferences v0 = this.a.getSharedPreferences("monitor_config", 0);
        String v1 = v0.getString("monitor_net_config", null);
        this.t = v0.getLong("monitor_configure_refresh_time", 0);
        if (v1 != null && !TextUtils.isEmpty(((CharSequence) v1))) {
            try {
                ag = true;
                this.a(new JSONObject(v1));
            } catch (Exception v0_1) {
                Log.e("monitor_config", "配置信息读取失败");
            }
        }

        if (this.R == 1) {
            if (this.Q <= 10) {
                com.bytedance.framwork.core.a.c.a(this.a);
            } else {
                com.bytedance.framwork.core.a.c.a(this.a, this.Q);
            }

            com.bytedance.framwork.core.a.c.a().c = this.s;
            this.r();
        }

        this.q();
        Context v0_2 = this.a;
        try {
            IntentFilter v1_1 = new IntentFilter();
            v1_1.addAction("android.net.conn.CONNECTIVITY_CHANGE");
            v1_1.addAction("is_background");
            v1_1.addAction("is_foreground");
            v0_2.registerReceiver(this.ai, v1_1);
        } catch (Throwable v0_3) {
        }
    }

    public static void a(c$c arg1) {
        if (arg1 != null) {
            try {
                if (aa.contains(arg1)) {
                    return;
                }

                aa.add(arg1);
            } catch (Throwable v0) {
            }
        }
    }

    public static void a(String arg4, String arg5, String arg6, float arg7) {
        try {
            JSONObject v0_1 = new JSONObject();
            v0_1.put("type", arg5);
            v0_1.put("key", arg6);
            v0_1.put("value", ((double) arg7));
            android.support.design.a.b(arg4, v0_1);
        } catch (Throwable v0) {
        }
    }

    public static void a(Context arg4, String arg5, long arg6, long arg8, long arg10, int arg12) {
        if (arg4 != null) {
            try {
                SharedPreferences.Editor v0_1 = arg4.getSharedPreferences("traffic_monitor_info", 0).edit();
                if (!TextUtils.isEmpty(((CharSequence) arg5))) {
                    v0_1.putString("net_type", arg5);
                }

                v0_1.putLong("mobile_traffic", arg6);
                v0_1.putLong("wifi_traffic", arg8);
                v0_1.putLong("last_total_traffic", arg10);
                v0_1.putLong("collect_traffic_time", System.currentTimeMillis());
                v0_1.putInt("traffic_upload_switch", arg12);
                v0_1.apply();
            } catch (Throwable v0) {
            }
        }
    }

    private synchronized void a(JSONObject arg8) {
        ArrayList v1_3;
        String v5;
        int v1_1;
        int v4;
        JSONArray v3;
        ArrayList v2;
        int v0 = 0;
        if (arg8 != null) {
            try {
                if (arg8.length() > 0) {
                    v2 = new ArrayList();
                    try {
                        v3 = arg8.optJSONArray("api_black_list");
                        if (v3 == null) {
//                            goto label_30;
                        } else if (v3.length() > 0) {
                            v4 = v3.length();
                            v1_1 = 0;
                            while (true) {
                                label_22:
                                if (v1_1 < v4) {
                                    v5 = v3.getString(v1_1);
                                    if (!TextUtils.isEmpty(((CharSequence) v5))) {
                                        ((List) v2).add(v5);
                                    }
                                    ++v1_1;
                                    continue;
                                } else {
//                                    goto label_30;
                                    break;
                                }
                            }
                        } else {
//                            goto label_30;
                        }
                    } catch (Exception v1) {
                        v1.printStackTrace();
                    }
                } else {
                    this.D = null;
                    this.f = null;
                    this.E = null;
                    return;
                }
                if (!((List) v2).isEmpty()) {
                    this.D = ((List) v2);
                } else {
                    List v1_2 = null;
                    this.D = v1_2;
                }
                v2 = new ArrayList();
                try {
                    v3 = arg8.optJSONArray("api_allow_list");
                    if (v3 == null) {
//                        goto label_56;
                    } else if (v3.length() <= 0) {
//                        goto label_56;
                    } else {
                        v4 = v3.length();
                        v1_1 = 0;
                        while (true) {
                            label_42:
                            if (v1_1 >= v4) {
                                break;
                            }
                            v5 = v3.getString(v1_1);
                            if (!TextUtils.isEmpty(v5)) {
                                ((List) v2).add(v5);
                            }
                            ++v1_1;
                            continue;
                        }
                    }
                } catch (Exception v1) {
                    v1.printStackTrace();
                }
//                label_56:
                if (!((List) v2).isEmpty()) {
                    this.f = ((List) v2);
                } else {
                    this.f = null;
                }
                v2 = new ArrayList();
                try {
                    v3 = arg8.optJSONArray("image_allow_list");
                    if (v3 == null) {
//                        goto label_79;
                    } else if (v3.length() <= 0) {
//                        goto label_79;
                    } else {
                        v4 = v3.length();
                        v1_1 = 0;
                        while (true) {
                            label_68:
                            if (v1_1 >= v4) {
                                break;
                            }
                            v5 = v3.getString(v1_1);
                            if (!TextUtils.isEmpty(((CharSequence) v5))) {
                                ((List) v2).add(v5);
                            }
                            ++v1_1;
                            continue;
                        }
                    }
                } catch (Exception v1) {
                    v1.printStackTrace();
                }
                if (!((List) v2).isEmpty()) {
                    this.F = v2;
                } else {
                    this.F = null;
                }

                v1_3 = new ArrayList();
                try {
                    JSONArray v2_1 = arg8.optJSONArray("report_host_new");
                    if (v2_1 == null) {
//                        goto label_104;
                    } else if (v2_1.length() <= 0) {
//                        goto label_104;
                    } else {
                        int v3_1 = v2_1.length();
                        while (true) {
                            label_90:
                            if (v0 >= v3_1) {
                                break;
                            }

                            String v4_1 = v2_1.getString(v0);
                            if (!TextUtils.isEmpty(((CharSequence) v4_1)) && v4_1.indexOf(46) > 0) {
                                ((List) v1_3).add(v4_1);
                            }
                            ++v0;
                            continue;
                        }
                    }
                } catch (Exception v0_2) {
                    v0_2.printStackTrace();
                }
                this.E = !((List) v1_3).isEmpty() ? ((List) v1_3) : null;
                this.u = arg8.optLong("fetch_setting_interval", 1200);
                this.v = arg8.optInt("polling_interval", 120);
                this.w = arg8.optInt("once_max_count", 100);
                this.x = arg8.optInt("max_retry_count", 4);
                this.y = arg8.optInt("report_fail_base_time", 15);
                this.c = arg8.optInt("disable_report_error", 0);
                this.d = arg8.optInt("enable_net_stats", 0);
                this.z = arg8.optInt("common_monitor_switch", 1);
                this.A = arg8.optInt("debug_real_switch", 1);
                this.H = arg8.optLong("mem_monitor_interval", 30);
                this.J = arg8.optLong("cpu_monitor_interval", 300);
                this.K = arg8.optLong("cpu_sample_interval", 60);
                L = arg8.optInt("log_send_switch", 1);
                this.M = arg8.optLong("more_channel_stop_interval", 1800);
                this.P = arg8.optBoolean("log_remvove_switch", false);
                this.j = arg8.optBoolean("android_collect_traffic_switch", true);
                this.B = arg8.optJSONObject("allow_log_type");
                this.C = arg8.optJSONObject("allow_metric_type");
                this.e = arg8.optJSONObject("allow_service_name");
                this.R = arg8.optInt("is_init_trace_module_switch", 1);
                this.Q = arg8.optLong("every_file_limited_size", 0);
                this.S = arg8.optInt("upload_trace_log_switch", 0);
                this.i = arg8.optInt("store_trace_log", 1);
                this.X = arg8.optBoolean("monitor_encrypt_switch", true);
                this.Y = arg8.optLong("image_sample_interval", 120);
                this.ae = arg8.optBoolean("upload_debug_switch", true);
                this.af = arg8.optBoolean("upload_file_switch", true);
                this.k = arg8.optString("file_upload_url", null);
                this.l = arg8.optLong("caton_interval", 500);
                if (this.b != null) {
                    this.b.a();
                }

                this.r();
                return;
            } catch (Throwable v0_1) {
                v0_1.printStackTrace();
            }
        }
        this.D = null;
        this.f = null;
        this.E = null;
        return;
    }

    static long a(c arg1, long arg2) {
        arg1.n = arg2;
        return arg2;
    }

    static String a(c arg0, String arg1) {
        arg0.m = arg1;
        return arg1;
    }

    private static String a(String arg2, String arg3) {
        try {
            return URLEncoder.encode(arg2, arg3);
        } catch (UnsupportedEncodingException v0) {
            throw new IllegalArgumentException(((Throwable) v0));
        }
    }

    static void a(Context arg10, String arg11, long arg12, long arg14, long arg16) {
        a(arg10, arg11, arg12, arg14, arg16, 1);
    }

    static void a(c arg4, JSONObject arg5) {
        if (arg5.length() > 0) {
            try {
                arg4.a(arg5.getJSONObject("data"));
                SharedPreferences.Editor v0_1 = arg4.a.getSharedPreferences("monitor_config", 0).edit();
                v0_1.putLong("monitor_configure_refresh_time", System.currentTimeMillis());
                v0_1.putString("monitor_net_config", arg5.getJSONObject("data").toString());
                v0_1.apply();
                if (ag) {
                    return;
                }

                ag = true;
                com.bytedance.framwork.core.monitor.a.a().b();
            } catch (Throwable v0) {
            }
        }
    }

    public static void a(JSONObject arg3, JSONObject arg4) {
        if (arg3 != null && arg4 != null && arg4.length() > 0) {
            try {
                Iterator v1 = arg4.keys();
                while (v1.hasNext()) {
                    Object v0_1 = v1.next();
                    arg3.put(((String) v0_1), arg4.get(((String) v0_1)));
                }
            } catch (JSONException v0) {
                v0.printStackTrace();
            }
        }
    }

    public static boolean a(Context arg2, JSONObject arg3, com.bytedance.framwork.core.monitor.c.c$b arg4) {
        Class v1;
        if (r == null) {
            v1 = c.class;
            synchronized (v1) {
                if (r == null) {
                    if (arg2 != null && arg3.length() > 0) {
                        r = new c(arg2, arg3, arg4);
//                        goto label_15;
                    } else {
                        boolean v0_1 = false;
                        return v0_1;
                    }
                }
            }
        }

        if (ag) {
            com.bytedance.framwork.core.monitor.a.a().b();
        }

        c v0_2 = r;
        try {
            String v1_1 = "caton_monitor";
            if (!v0_2.b(v1_1)) {
                return true;
            }

            int v1_2 = 21;
            if (Build.VERSION.SDK_INT < v1_2) {
                return true;
            }

            com.bytedance.article.common.a.a.a.a();
            com.bytedance.article.common.a.a.a.b();
        } catch (Throwable v0) {
        }

        return true;
    }

    static boolean a(c arg1) {
        return arg1.X;
    }

    public final int a() {
        int v0 = this.v <= 0 ? 120 : this.v;
        return v0;
    }

    public final l a(String arg17, byte[] arg18, String arg19) {
        l v2_6 = null;
        com.bytedance.article.common.a.b.a.a$a v2_4 = null;
        Object v2_3 = null;
        long v8;
        JSONObject v4 = null;
        l v3 = new l();
        try {
            byte[] v2_1 = NetworkDemo.a(d(arg17), arg18, MonitorNetUtil$CompressType.GZIP, arg19, this.X);
            this.V = 0;
            this.U = 0;
            v3.a = 200;
            v4 = new JSONObject(new String(v2_1));
            if (v4.length() <= 0) {
                v3.b = v4;
                v2_6 = v3;
                return v2_6;
            }

            JSONObject v5 = v4.optJSONObject("configs");
            if (v5 == null) {
                v3.b = v4;
                v2_6 = v3;
                return v2_6;
            }

            if (v5.length() <= 0) {
                v3.b = v4;
                v2_6 = v3;
                return v2_6;
            }

            JSONObject v2_2 = v5.optJSONObject("debug_settings");
            if (v2_2 != null && v2_2.length() > 0 && (this.ae)) {
                com.bytedance.article.common.a.b.a v6 = this.ac;
                if (v2_2 != null && v2_2.length() > 0 && v2_2.optInt("should_submit_debugreal", 0) != 0) {
                    if ((v2_2.optBoolean("wifi_only", true)) && !PackageUtils.a(v6.a)) {
//                        goto label_44;
                    } else if (!NetworkDemo.c(v6.a)) {
//                        goto label_44;
                    } else {
                        String v7 = v2_2.optString("upload_type", "debug_log");
                        v8 = System.currentTimeMillis();
                        if (TextUtils.isEmpty(((CharSequence) v7))) {
                            v2_3 = null;
                        } else if (com.bytedance.article.common.a.b.a.b.containsKey(v7)) {
                            v2_3 = com.bytedance.article.common.a.b.a.b.get(v7);
                        } else {
                            v2_4 = new com.bytedance.article.common.a.b.a.a$a();
                            com.bytedance.article.common.a.b.a.b.put(v7, v2_4);
                        }

                        if (v2_4 == null) {
//                        goto label_44;
                        } else if (v2_4.b) {
//                        goto label_44;
                        } else if (v8 - v2_4.a < 600000) {
//                        goto label_44;
                        } else {
                            v2_4.b = true;
                            v2_4.a = v8;
                            com.bytedance.frameworks.core.thread.c.a();
                            com.bytedance.frameworks.core.thread.c.a(new com.bytedance.article.common.a.b.b(v6, v7, v2_4));
                        }
                    }
                }
            }

//            label_44:
            v2_2 = v5.optJSONObject("file_settings");
            if (v2_2 == null) {
                v3.b = v4;
                v2_6 = v3;
                return v2_6;
            }

            if (v2_2.length() <= 0) {
                v3.b = v4;
                v2_6 = v3;
                return v2_6;
            }

            if (!this.af) {
                v3.b = v4;
                v2_6 = v3;
                return v2_6;
            }

            if (v2_2 == null) {
                v3.b = v4;
                v2_6 = v3;
                return v2_6;
            }

            if (v2_2.length() <= 0) {
                v3.b = v4;
                v2_6 = v3;
                return v2_6;
            }

            if (v2_2.optInt("should_upload_file", 0) == 0) {
                v3.b = v4;
                v2_6 = v3;
                return v2_6;
            }

            String v5_1 = v2_2.optString("type", null);
            long v6_1 = v2_2.optLong("limit_file_size", 61644800);
            if ((v2_2.optBoolean("wifi_only", true)) && !PackageUtils.a(com.bytedance.article.common.a.c.a.a)) {
                v3.b = v4;
                v2_6 = v3;
                return v2_6;
            }

            if (!NetworkDemo.c(com.bytedance.article.common.a.c.a.a)) {
                v3.b = v4;
                v2_6 = v3;
                return v2_6;
            }

            if (TextUtils.isEmpty(((CharSequence) v5_1))) {
                v3.b = v4;
                v2_6 = v3;
                return v2_6;
            }

            if (TextUtils.isEmpty(((CharSequence) v5_1))) {
                v2_3 = null;
            } else if (com.bytedance.article.common.a.c.a.b.containsKey(v5_1)) {
                v2_3 = com.bytedance.article.common.a.c.a.b.get(v5_1);
            } else {
                com.bytedance.article.common.a.c.a.a$a v2_5 = new com.bytedance.article.common.a.c.a.a$a();
                com.bytedance.article.common.a.c.a.b.put(v5_1, v2_5);
            }

            if (v2_3 == null) {
                v3.b = v4;
                v2_6 = v3;
                return v2_6;
            }

            v8 = ((com.bytedance.article.common.a.c.a.a$a) v2_3).a;
            boolean v10 = ((com.bytedance.article.common.a.c.a.a$a) v2_3).b;
            long v12 = System.currentTimeMillis();
            if (v12 - v8 < 600000) {
                v3.b = v4;
                v2_6 = v3;
                return v2_6;
            }

            if (v10) {
                v3.b = v4;
                v2_6 = v3;
                return v2_6;
            }

            ((com.bytedance.article.common.a.c.a.a$a) v2_3).b = true;
            ((com.bytedance.article.common.a.c.a.a$a) v2_3).a = v12;
            com.bytedance.frameworks.core.thread.c.a();
            com.bytedance.frameworks.core.thread.c.a(new com.bytedance.article.common.a.c.b(v5_1, v6_1));
            v3.b = v4;
            v2_6 = v3;
            return v2_6;
        } catch (Throwable v2) {
            v3.a = (v2 instanceof HttpResponseException) ? ((HttpResponseException) v2).getStatusCode() : -1;
            if (v3.a == 503 || v3.a == 509) {
                Log.e("monitor_response_code", "response code " + v3.a);
                this.W = true;
                this.T = System.currentTimeMillis();
                if (this.b != null) {
                    this.b.a(false);
                }

                if (this.V == 0) {
                    this.U = 300000;
                } else if (this.V == 1) {
                    this.U = 900000;
                } else {
                    this.U = 1800000;
                }

                ++this.V;
                this.ae = false;

                v2.printStackTrace();
                label_28:
                v3.b = v4;
                v2_6 = v3;
                return v2_6;
            }
        }
        return v2_6;
    }

    public final JSONObject a(String arg5, long arg6, long arg8, String arg10, String arg11, String arg12, int arg13) {
        JSONObject v0 = null;
        if (!TextUtils.isEmpty(((CharSequence) arg5))) {
            try {
                JSONObject v1_1 = new JSONObject();
                v1_1.put("log_type", arg5);
                v1_1.put("duration", arg6);
                if (!TextUtils.isEmpty(((CharSequence) arg10))) {
                    v1_1.put("uri", Uri.parse(arg10));
                }

                if (arg8 > 0) {
                    v1_1.put("timestamp", arg8);
                }

                v1_1.put("status", arg13);
                if (!TextUtils.isEmpty(((CharSequence) arg11))) {
                    v1_1.put("ip", arg11);
                }

                if (!TextUtils.isEmpty(((CharSequence) arg12))) {
                    v1_1.put("trace_code", arg12);
                } else {
                    v1_1.put("trace_code", "");
                }

                v1_1.put("network_type", NetworkDemo.b(this.a.getApplicationContext()).getValue());
                v0 = v1_1;
            } catch (Exception v1) {
            }
        }

        return v0;
    }

    public final boolean a(String arg4) {
        boolean v0;
        if (arg4 == null || this.D == null || this.D.size() == 0) {
            v0 = false;
        } else {
            Iterator v2 = this.D.iterator();
            do {
                if (v2.hasNext()) {
                    if (!arg4.contains((String) v2.next())) {
                        continue;
                    }

                    break;
                } else {
                    return false;
                }
            }
            while (true);

            v0 = true;
            return v0;
        }

        return v0;
    }

    public final boolean b(String arg3) {
        boolean v0 = false;
        if (this.B != null && !TextUtils.isEmpty(((CharSequence) arg3)) && this.B.opt(arg3) != null) {
            v0 = true;
        }

        return v0;
    }

    static long b(c arg1, long arg2) {
        arg1.o = arg2;
        return arg2;
    }

    static boolean b(c arg1) {
        return arg1.j;
    }

    public final int b() {
        int v0 = this.w <= 0 ? 100 : this.w;
        return v0;
    }

    public final boolean c(String arg3) {
        boolean v0 = false;
        if (this.C != null && !TextUtils.isEmpty(((CharSequence) arg3)) && this.C.opt(arg3) != null) {
            v0 = true;
        }

        return v0;
    }

    static long c(c arg1, long arg2) {
        arg1.p = arg2;
        return arg2;
    }

    static String c(c arg1) {
        return arg1.m;
    }

    public final List c() {
        List v0 = this.E == null || (this.E.isEmpty()) ? Arrays.asList(new String[]{"http://mon.snssdk.com/monitor/collect/", "http://mon.toutiao.com/monitor/collect/", "http://mon.toutiaocloud.com/monitor/collect/", "http://mon.toutiaocloud.net/monitor/collect/"}) : this.E;
        return v0;
    }

    public static String d(String arg6) {
        String v1;
        if ((TextUtils.isDigitsOnly(arg6)) || N == null) {
            v1 = arg6;
        } else {
            if (arg6.indexOf("?") < 0) {
                arg6 = arg6 + "?";
            }
            String v0 = arg6.endsWith("?") ? arg6 + a("sdk_version", "UTF-8") + "=" + a("400", "UTF-8") : arg6 + "&" + a("sdk_version", "UTF-8") + "=" + a("400", "UTF-8");
            Map v2 = com.bytedance.framwork.core.monitor.c.c$b.a();

            if (v2.size() > 0) {
                Iterator v3 = v2.entrySet().iterator();
                for (v1 = v0; true; v1 = v0) {
                    label_38:
                    if (!v3.hasNext()) {
                        return v1;
                    }

                    Object v0_1 = v3.next();
                    if (v2.get(((Map.Entry) v0_1).getKey()) == null) {
                        v0 = v1;
                    } else if (v1.endsWith("?")) {
                        v1 = v1 + a(((Map.Entry) v0_1).getKey().toString(), "UTF-8") + "=" + a(v2.get(((Map.Entry) v0_1).getKey()).toString(), "UTF-8");
                        v0 = v1;
                        continue;
                    } else {
                        v0 = v1 + "&" + a(((Map.Entry) v0_1).getKey().toString(), "UTF-8") + "=" + a(v2.get(((Map.Entry) v0_1).getKey()).toString(), "UTF-8");
                    }
                }
            }

            v1 = v0;
        }

        return v1;
    }

    static long d(c arg2) {
        return arg2.n;
    }

    public final JSONObject d() {
        return this.s;
    }

    static long e(c arg2) {
        return arg2.o;
    }

    public final int e() {
        return this.x <= 0 ? 4 : this.x;
    }

    public final boolean e(String arg5) {
        boolean v0_1;
        if (this.F != null && this.F.size() != 0 && !TextUtils.isEmpty(((CharSequence) arg5))) {
            try {
                String v2 = Uri.parse(arg5).getHost();
                Iterator v3 = this.F.iterator();
                do {
                    if (v3.hasNext()) {
                        if (!v2.equalsIgnoreCase((String) v3.next())) {
                            continue;
                        }
                        break;
                    } else {
                        return false;
                    }
                }
                while (true);
            } catch (Throwable v0) {
                return false;
            }

            v0_1 = true;
            return v0_1;
        } else {
            v0_1 = false;
        }

        return v0_1;
    }

    static long f(c arg2) {
        return arg2.p;
    }

    public final int f() {
        int v0 = this.y <= 0 ? 15 : this.y;
        return v0;
    }

    public final long g() {
        long v0 = this.M == 0 ? 1800000 : this.M * 1000;
        return v0;
    }

    public final boolean h() {
        boolean v0 = this.W ? this.W : this.P;
        return v0;
    }

    public final void i() {
        long v0_2;
        long v4;
        long v2;
        if (System.currentTimeMillis() - this.T > this.U) {
            this.W = false;
            if (this.b != null) {
                this.b.a(true);
            }
        }

        if (this.c("mem_monitor")) {
            v2 = System.currentTimeMillis();
            if ((v2 - this.G) / 1000 > this.H) {
                if (this.b != null) {
                    v4 = ((long) android.support.design.a.a(Process.myPid(), this.a));
                    Context v0 = this.a;
                    int v0_1 = v0 == null ? -1 : ((ActivityManager) v0.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
                    v0_2 = ((long) v0_1);
                    if (v4 > 0 && (k())) {
                        if (!android.support.design.a.e(this.a, this.a.getPackageName())) {
                            this.b.c("mem_monitor", "dalvik_mem_used_background", ((float) (v4 / 1024)));
                        } else {
                            this.b.c("mem_monitor", "dalvik_mem_used_foreground", ((float) (v4 / 1024)));
                        }
                    }

                    if (v4 <= 0) {
//                        goto label_69;
                    } else if (v0_2 <= 0) {
//                        goto label_69;
                    } else if (!k()) {
//                        goto label_69;
                    } else if (!android.support.design.a.e(this.a, this.a.getPackageName())) {
                        this.b.c("mem_monitor", "dalvikmem_background_used_rate", ((float) ((((double) v4)) / 1024 / (((double) v0_2)))));
//                        goto label_69;
                    } else {

                        this.b.c("mem_monitor", "dalvikmem_foreground_used_rate", ((float) ((((double) v4)) / 1024 / (((double) v0_2)))));
                    }
                }

                label_69:
                this.G = v2;
            }
        }

        if (!this.c("cpu_monitor")) {
//            goto label_101;
        } else {
            v2 = System.currentTimeMillis();
            if ((v2 - this.I) / 1000 < this.K) {
//            goto label_101;
            } else {
                this.I = v2;
                v0_2 = android.support.design.a.d();
                v4 = android.support.design.a.a(Process.myPid());
                long v6 = 360;
                try {
                    Thread.sleep(v6);
                } catch (InterruptedException v6_1) {
                    v6_1.printStackTrace();
                }

                double v4_1 = (((double) (android.support.design.a.a(Process.myPid()) - v4))) / (((double) (android.support.design.a.d() - v0_2)));
                if (this.ah == null) {
                    this.ah = new c$a(v2, v4_1, v4_1, v4_1);
//            goto label_101;
                } else {
                    ++this.ah.b;
                    this.ah.e += v4_1;
                    if (this.ah.d > v4_1) {
                        this.ah.d = v4_1;
                    }

                    if (this.ah.c < v4_1) {
                        this.ah.c = v4_1;
                    }

                    if ((v2 - this.ah.a) / 1000 <= this.J) {
//            goto label_101;
                    } else {
                        if (this.b != null && (k())) {
                            this.b.c("cpu_monitor", "cpu_rate_avg", ((float) (this.ah.e / (((double) this.ah.b)))));
                            this.b.c("cpu_monitor", "cpu_rate_max", ((float) this.ah.c));
                        }
                        this.ah = null;
                    }
                }
            }
        }
        try {
//            label_101:
            Iterator v1 = aa.iterator();
            while (v1.hasNext()) {
                ((c$c) v1.next()).c();
            }
        } catch (Throwable v0_3) {
        }

        if (!this.Z && this.b != null && (this.c("storageUsed"))) {
            this.Z = true;
            float v0_4 = android.support.design.a.g(this.a);
            float v1_1 = android.support.design.a.h(this.a);
            if (v0_4 > 0f) {
                this.b.c("storageUsed", "data", v0_4);
            }

            if (v1_1 <= 0f) {
//                goto label_116;
            } else {
                this.b.c("storageUsed", "cache", v1_1);
            }
        }

        label_116:
        if (this.u > 0) {
            this.q();
        }
    }

    public static com.bytedance.framwork.core.monitor.c j() {
        return ag ? r : null;
    }

    public static boolean k() {
        boolean v0 = true;
        if (L != 1) {
            v0 = false;
        }

        return v0;
    }

    public final JSONObject l() {
        try {
            if (this.s == null) {
                return null;
            }

            HashSet v0_1 = new HashSet();
            Iterator v1 = this.s.keys();
            while (v1.hasNext()) {
                ((Set) v0_1).add(v1.next());
            }

            JSONObject v0_2 = new JSONObject(this.s, (String[]) ((Set) v0_1).toArray(new String[((Set) v0_1).size()]));
            return v0_2;
        } catch (Throwable v0) {
            v0.printStackTrace();
        }

        return null;
    }

    static com.bytedance.framwork.core.monitor.c.c$b m() {
        return N;
    }

    static List n() {
        return O;
    }

    static boolean o() {
        return ag;
    }

    static boolean p() {
        ag = true;
        return true;
    }

    private void q() {
        long v2 = 600;
        if (this.u < v2) {
            this.u = v2;
        }

        if ((System.currentTimeMillis() - this.t) / 1000 > this.u) {
            Class v1 = c.class;
            synchronized (v1) {
                this.t = System.currentTimeMillis();
            }

            if (!NetworkDemo.c(this.a)) {
                return;
            }

            try {
                com.bytedance.frameworks.core.thread.c.a();
                com.bytedance.frameworks.core.thread.c.a(new com.bytedance.framwork.core.monitor.d(this));
            } catch (Throwable v0) {
            }
        }
    }

    private void r() {
        if (this.S == 1 && com.bytedance.framwork.core.a.c.a() != null) {
            try {
                com.bytedance.frameworks.core.thread.c.a();
                com.bytedance.frameworks.core.thread.c.a(new com.bytedance.framwork.core.a.b());
            } catch (Throwable v0) {
            }
        }
    }
}

